﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using sdm.exam.domain;
using sdm.exam.domain.Abstract;
using sdm.exam.domain.DataContext;
using sdm.exam.domain.Entities;

namespace sdm.exam.test.Domain
{
    [TestClass]
    public class ClassRoomDomainTest
    {
        [TestMethod]
        public void AddClassRoomTest()
        {
            Ninjector.Kernel.Bind<ISdmExamRepository>().ToConstant(new DataContext(ConnectionStrings.TestConnection));

            var domain = new ClassRoomDomain();
            bool hasClassRoom = false;
            string classRoomName = "testAdd";
            var classroom = new Classroom();
            classroom.Name = classRoomName;
            domain.AddClassRoom(classroom);

            List<Classroom> classRoomList = domain.GetClassRooms();
            foreach (var classRoom in classRoomList)
            {
                if (classRoom.Name == classRoomName)
                {
                    hasClassRoom = true;
                    break;
                } 
            }
            Assert.AreEqual(true, hasClassRoom);
        }

        [TestMethod]
        public void GetClassRoomTest()
        {
            Ninjector.Kernel.Bind<ISdmExamRepository>().ToConstant(new DataContext(ConnectionStrings.TestConnection));

            var domain = new ClassRoomDomain();
            bool hasClassRoom=false;
            string classRoomName = "testGet";
            var classroom = new Classroom();
            classroom.Name = classRoomName;
            domain.AddClassRoom(classroom);

            List<Classroom> classRoomList = domain.GetClassRooms();
            foreach (var classRoom in classRoomList)
            {
                if (classRoom.Name == classRoomName)
                {
                    hasClassRoom = true;
                    break;
                } 
                    
            }
            Assert.AreEqual(true, hasClassRoom);
        }

        [TestMethod]
        public void DeleteClassRoomTest()
        {
            Ninjector.Kernel.Bind<ISdmExamRepository>().ToConstant(new DataContext(ConnectionStrings.TestConnection));

            var domain = new ClassRoomDomain();

            string classRoomName = "testDelete";
            bool hasBeenDeleted = true;

            var classroom = new Classroom();
            classroom.Name = classRoomName;

            domain.DeleteClassRoom(classRoomName);

            List<Classroom> classRoomList = domain.GetClassRooms();

            foreach (var classRoom in classRoomList)
            {
                if (classRoom.Name == classRoomName)
                {
                    hasBeenDeleted = false;
                    break;
                }

            }
            Assert.AreEqual(false, hasBeenDeleted);
        }
    }
}
